package br.senac.sp.uniobjetos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import br.senac.sp.persistence.AbstractRelationalDBMapper;

public class AlunoMapper extends AbstractRelationalDBMapper<Aluno, Integer> {

    public AlunoMapper() {
        super("ALUNO");
    }

    @Override
    protected Aluno getObjectFromRecord(Integer oid, ResultSet record) throws SQLException {
        Aluno aluno = new Aluno();
        aluno.setIdAluno(oid);
        aluno.setIdade(record.getInt("IDADE"));
        aluno.setRg(record.getInt("RG"));
        aluno.setSexo(record.getInt("SEXO"));
        aluno.setNome(record.getString("NOME"));
        return aluno;
    }

    @Override
    protected Map<String, Object> getInfoFromObject(Aluno entity) {
        Map<String, Object> info = new HashMap<String, Object>();
        info.put("IDADE", entity.getIdade());
        info.put("RG", entity.getRg());
        info.put("SEXO", entity.getSexo());
        info.put("NOME", entity.getNome());
        return info;
    }

    @Override
    protected Integer getIdFromObject(Aluno aluno) {
        return aluno.getIdAluno();
    }

    @Override
    protected String getUniqueIdentifierArguments() {
        return "ID";
    }

}
